"""
网址
"""
ths_api_search=['概念板块换手率排名前10','股票所属行业','20210903价格大于250天均线且换手率大于3']
""" 已经失效，代替方案
ths_api={'url':'http://ai.iwencai.com/urp/v7/landing/getDataList',
         'headers':{'Accept':'application/json',
        'Accept-Encoding':'gzip, deflate',
        'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6',
        'Connection':'keep-alive',
        'Content-Length':'1205',
        'Content-Type':'application/x-www-form-urlencoded',
        'Host':'ai.iwencai.com',
        'Origin':'http://www.iwencai.com',
        'Referer':'http://www.iwencai.com/unifiedmobile/',
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36'},
        'params':{  'query':'',
                    'urp_sort_index':'',
                    'urp_sort_way':'desc',
                    'condition':"",
                    'codelist':'',
                    'is_cache':'1',
                    'perpage':'1000',
                    'page':'1',
                    'logid':'738e719788328bebded79765735ecdf3',
                    'ret':'json_all',
                    'sessionid':'',
                    'iwc_token':'',
                    'urp_use_sort':'1',
                    'user_id':'80738749',
                    'uuids[0]':'18369',
                    'query_type':'stock',
                    'comp_id':'5716439',
                    'business_cat':'soniu',
                    'uuid':'18369'}
         }
"""
"""
import requests
import simplejson
import json
import re
import pandas as pd

pd.set_option('display.max_rows', None)
pd.set_option('display.width', 5000)

#网站http://www.iwencai.com/unifiedwap/result?w=%E4%BA%BA%E6%B0%942021.2.3&querytype=&issugs
#http://www.iwencai.com/unifiedmobile/#/result?question=%E4%BA%BA%E6%B0%942021.3.2&queryType=&sign=1626576240283
url ='http://ai.iwencai.com/urp/v7/landing/getDataList'
headers = {}
params ={
'query':'人气排行2021.09.07',
'urp_sort_index':'',
'urp_sort_way':'desc',
'condition':"",
'codelist':'',
'is_cache':'1',
'perpage':'1000',
'page':'1',
'logid':'738e719788328bebded79765735ecdf3',
'ret':'json_all',
'sessionid':'',
'iwc_token':'',
'urp_use_sort':'1',
'user_id':'80738749',
'uuids[0]':'18369',
'query_type':'stock',
'comp_id':'5716439',
'business_cat':'soniu',
'uuid':'18369'}

#'iwc_token':'0ac9529a16265750150008475', 这个是加密，

res_comment = requests.post(url,headers = headers,data=params)        # 调用get方法，下载评论列表
res_comment=res_comment.text
json_list= json.loads(res_comment)["answer"]["components"][0]["data"]["datas"]
pd.DataFrame(json_list)
"""
top_100={"同花顺":{"url":"https://basic.10jqka.com.cn/api/stockph/popularity/top/",'headers':{'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.2 Safari/537.36'}},
         "东方财富": {"url": "https://emappdata.eastmoney.com/stockrank/getAllCurrentList",'headers':{},'params' :{'appId': "appId01", 'globalId': "786e4c21-70dc-435a-93bb-39", 'pageNo': '1', 'pageSize': '100'}}
        }
        #--> print(top_100["同花顺"]["headers"])
"""
1.同花顺top100
    #同花顺人气排名TOP100
    #https://basic.10jqka.com.cn/basicph/popularityRanking.html?fontzoom=no&client_userid=5sLPT&share_hxapp=gsc&share_action=webpage_share.1&back_source=wxhy
    url = "https://basic.10jqka.com.cn/api/stockph/popularity/top/"
    headers={'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'Cookie': 'v=A_nOCr7EvcWz-mFRdDTuBY8ICG7QBu241_oRTBsudSCfohOYY1b9iGdKIR2o',
    'Host': 'basic.10jqka.com.cn',
    'If-Modified-Since': 'Thu, 18 Feb 2021 05:46:40 GMT',
    'sec-ch-ua': '"\\Not;A\"Brand";v="99", "Google Chrome";v="85", "Chromium";v="85"',
    'sec-ch-ua-mobile': '?0',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'none',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.2 Safari/537.36'

    }
    r = requests.get(url, headers = headers)
    
2. #东方财富人气排名TOP100  #https://vipmoney.eastmoney.com/collect/stockranking/pages/ranking/list.html
    url = "https://emappdata.eastmoney.com/stockrank/getAllCurrentList"#https://vipmoney.eastmoney.com/collect/stockranking/pages/ranking/list.html
    headers={
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': '85',
    'Content-Type': 'application/json',
    'Host': 'emappdata.eastmoney.com',
    'Origin': 'https://vipmoney.eastmoney.com',
    'Referer': 'https://vipmoney.eastmoney.com/',
    'sec-ch-ua': '"\\Not;A\"Brand";v="99", "Google Chrome";v="85", "Chromium";v="85"',
    'sec-ch-ua-mobile': '?0',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.2 Safari/537.36'

    }
    params = {'appId': "appId01", 'globalId': "786e4c21-70dc-435a-93bb-39", 'pageNo': '1', 'pageSize': '100'}
    r = requests.post(url, headers = headers,json =params)
    result_=pd.DataFrame(json.loads(r.text)['data'])
    today_time_save=other.time_saveandget().tolist()[-1]
    print("东方财富top",result_)
    result_.to_csv("data_gp/lishidata/top100/{}_{}_{}_{}.txt".format(today_time_save[:4],today_time_save[4:6],today_time_save[6:],"dfcf_top100"),encoding = "utf-8")
3.东方财富暴力拉升X
def dfcf_biaosheng100():
    #https://vipmoney.eastmoney.com/collect/stockranking/pages/ranking/list.html
    url = "https://emappdata.eastmoney.com/stockrank/getAllHisRcList"#飙升榜
    headers={
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': '85',
    'Content-Type': 'application/json',
    'Host': 'emappdata.eastmoney.com',
    'Origin': 'https://vipmoney.eastmoney.com',
    'Referer': 'https://vipmoney.eastmoney.com/',
    'sec-ch-ua': '"\\Not;A\"Brand";v="99", "Google Chrome";v="85", "Chromium";v="85"',
    'sec-ch-ua-mobile': '?0',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.2 Safari/537.36'

    }
    params = {'appId': "appId01", 'globalId': "786e4c21-70dc-435a-93bb-38|", 'pageNo': '1', 'pageSize': '100'}
    r = requests.post(url, headers = headers,json =params)
    result_=pd.DataFrame(json.loads(r.text)['data'])
    today_time_save=other.time_saveandget().tolist()[-1]
    print("东方财富暴增",result_)
    result_.to_csv("data_gp/lishidata/top100/{}_{}_{}_{}.txt".format(today_time_save[:4],today_time_save[4:6],today_time_save[6:],"dfcf_biaosheng100"),encoding = "utf-8")
"""
dfcf_rank={"now实时":{"url":"https://emappdata.eastmoney.com/stockrank/getCurrentList",'headers':{},'params' :{'appId': "appId01", 'globalId': "786e4c21-70dc-435a-93bb-39"}},
            "his历史":{"url":"https://emappdata.eastmoney.com/stockrank/getHisList",'headers':{},'params' :{'appId': "appId01", 'globalId': "786e4c21-70dc-435a-93bb-39"}}
           }
"""
dfcf_rank 抓取网址
mainUrl = "http://mguba.eastmoney.com/mguba/list/{}".format(code)
#https://vipmoney.eastmoney.com/collect/stockranking/pages/ranking/stock.html?code=300001&market=0
def dfcf_gegu_shishi(code):#dfcf_gegu_shishi("SZ002968")
    #实时趋势
    url = "https://emappdata.eastmoney.com/stockrank/getCurrentList"#https://emappdata.eastmoney.com/stockrank/getCurrentList #https://emappdata.eastmoney.com/stockrank/getHisList
    headers={
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': '85',
    'Content-Type': 'application/json',
    'Host': 'emappdata.eastmoney.com',
    'Origin': 'https://vipmoney.eastmoney.com',
    'Referer': 'https://vipmoney.eastmoney.com/',
    'sec-ch-ua': '"\\Not;A\"Brand";v="99", "Google Chrome";v="85", "Chromium";v="85"',
    'sec-ch-ua-mobile': '?0',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.2 Safari/537.36'

    }
    params = {'appId': "appId01", 'globalId': "786e4c21-70dc-435a-93bb-38", 'srcSecurityCode': "{}".format(code)}
    r = requests.post(url, headers = headers,json =params)
    print(r.text)
def dfcf_gegu_lisi(code):#dfcf_gegu_lisi("SZ002968")
#历史趋势
    url = "https://emappdata.eastmoney.com/stockrank/getHisList"#https://emappdata.eastmoney.com/stockrank/getCurrentList #https://emappdata.eastmoney.com/stockrank/getHisList
    headers={
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': '85',
    'Content-Type': 'application/json',
    'Host': 'emappdata.eastmoney.com',
    'Origin': 'https://vipmoney.eastmoney.com',
    'Referer': 'https://vipmoney.eastmoney.com/',
    'sec-ch-ua': '"\\Not;A\"Brand";v="99", "Google Chrome";v="85", "Chromium";v="85"',
    'sec-ch-ua-mobile': '?0',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.2 Safari/537.36'

    }
    params = {'appId': "appId01", 'globalId': "786e4c21-70dc-435a-93bb-38", 'srcSecurityCode': "{}".format(code)}
    r = requests.post(url, headers = headers,json =params)
    print(r.text)
"""

dxw={"异动":{"url":'https://api.quchaogu.com/chart/bankuai/yidong?date=%20','headers':{}},

     "zhangting":'http://api.quchaogu.com/lhbapp/zhangting/index?&orderKey=bk_name&orderValue=desc&day={}',
    "zhangting_header":{'User-Agent': 'DxwApp:5.3.0.200 | android:5.1.1 | smartisan:DT1901A | sc:360,640 | did:a865166023406484 | oaid: | vaid: | did:a865166023406484 | idfa: | qd:update | av:8.9 | uid:7%253A9%253A276379544%253Aa865166023406484%253A6%253A1629468255%253Aec651ba786e046a | uuid:7079557765849349009232',
                        'Host': 'api.quchaogu.com',
                        'Connection': 'Keep-Alive',
                        'Accept-Encoding': 'gzip',
                        'Cookie': 'web_uinfo=%7B%22uactime%22%3A1629468270%7D; app_ua=DxwApp%3A5.3.0.200%20%7C%20android%3A5.1.1%20%7C%20smartisan%3ADT1901A%20%7C%20sc%3A360%2C640%20%7C%20did%3Aa865166023406484%20%7C%20oaid%3A%20%7C%20vaid%3A%20%7C%20did%3Aa865166023406484%20%7C%20idfa%3A%20%7C%20qd%3Aupdate%20%7C%20av%3A8.9%20%7C%20uid%3A7%25253A9%25253A276379544%25253Aa865166023406484%25253A6%25253A1629468255%25253Aec651ba786e046a%20%7C%20uuid%3A7079557765849349009232; vistor_uuid=49591559348606564836804; web_qtstr=7%3A9%3A276379544%3Aa865166023406484%3A6%3A1629468255%3Aec651ba786e046a',},
     "longhu":"https://api.quchaogu.com/dxwapp/lhb/index?&orderValue=1&orderKey=percent&date={}",
     #个股
     "个股_涨幅榜_涨幅":"http://api.quchaogu.comdxwapp/gegu/index?day={}&pagecount=20&type=1&page={}&apiversion=8.7&backgroundcolor=white&vaid=&oaid=",
    #板块
    "板块main_4chart":{"url":'https://api.quchaogu.com/chart/bankuai/yidong?date=%20','headers':{}},
    "板块main_list":{"url":'https://api.quchaogu.com//bk/rank/index?lhsj=0&pagecount=20&tab=0&day=20210903&szjh=0&page=2&type=0&kjjx=0&zg=0&apiversion=8.7&backgroundcolor=white&vaid=&oaid=','headers':{}},


    }
"""
#dxw api爬取    
def dxw_api_yidong():
    time_=other.time_saveandget().tolist()[-1]
    #https://api.quchaogu.com/chart/bankuai/yidong?date=%2020210301
    url ='https://api.quchaogu.com/chart/bankuai/yidong?date=%20{}'.format(time_)#https://api.quchaogu.com/chart/bankuai/yidong?date=
    "GET /chart/bankuai/yidong?date= HTTP/1.1
    Host: api.quchaogu.com
    Connection: keep-alive
    Origin: https://ch.quchaogu.com
    User-Agent: Mozilla/5.0 (Linux; Android 5.1.1; SM-G9730 Build/LMY48Z; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.100 Mobile Safari/537.36
    Accept: */*
    Referer: https://ch.quchaogu.com/v1.9.6/abnormal_change.html
    Accept-Encoding: gzip, deflate
    Accept-Language: zh-CN,en-US;q=0.8
    X-Requested-With: com.quchaogu.dxw"

    r = requests.get(url)
    if r.status_code==200:
        r=r.text.encode('utf-8').decode('unicode_escape')
        print("{}".format(time_),json.loads(r)['data']['name'])#{"code":10000,"msg":"succ","data":{"t":[1614648720,1614651780,1614655620,1614662640,1614666360,1614667380],"name":["碳中和","充电桩","金属钨","稀土永磁","芯片","航空制造"]}}
    result_=pd.DataFrame(json.loads(r)['data']['name'])
    today_time_save=other.time_saveandget().tolist()[-1]
    print("dxw移动",result_)
    result_.to_csv("data_gp/lishidata/top100/{}_{}_{}_{}.txt".format(today_time_save[:4],today_time_save[4:6],today_time_save[6:],"dxw_api_yidong"),encoding = "utf-8")
"""
if __name__ == '__main__':
    import requests
    # r = requests.get(top_100["同花顺"]["url"], headers=top_100["同花顺"]["headers"])
    # print(r.text)
    #
    # r = requests.post(top_100["东方财富"]["url"],headers=top_100["东方财富"]["headers"],json=top_100["东方财富"]["params"])
    # print(r.text)
    #
    # dfcf_rank["now实时"]['params']['srcSecurityCode'] = "SZ000002"
    # r=requests.post(dfcf_rank["now实时"]["url"], headers=dfcf_rank["now实时"]["headers"], json=dfcf_rank["now实时"]["params"])
    # print(r.text)
    # dfcf_rank["his历史"]['params']['srcSecurityCode'] = "SZ000002"
    # r=requests.post(dfcf_rank["his历史"]["url"], headers=dfcf_rank["his历史"]["headers"], json=dfcf_rank["his历史"]["params"])
    # print(r.text)
    #-------------------
    import requests
    list_a=dxw["龙虎榜"].format("")
    list_b="202020"
    list_url=[list_a,list_b]

    print(' '.join(list_url))

    print( '{}'.format(dxw["龙虎榜"]))
# 涨停 http://api.quchaogu.com/lhbapp/zhangting/index?&orderKey=bk_name&orderValue=desc&day=20210917
# 龙虎榜 https://api.quchaogu.com/dxwapp/lhb/index?orderValue=1&orderKey=percent&date=20210917
# Request_url
    import requests
    a=requests.get("https://api.quchaogu.com/dxwapp/lhb/index?orderValue=1&orderKey=percent&date=20210917")
    print(a.text)


